package com.ce.pms.report.service;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ce.pms.renovation.service.ICertificateManageService;
import com.ce.pms.renovation.vo.RenovateLicenceVO;
import com.ce.pms.report.queryvo.AlreadyChargeItemListQueryVO;
import com.ce.pms.report.queryvo.LicenceQueryVO;
import com.ce.report.entity.CEReportDataSet;
import com.ce.report.exception.CEReportException;
import com.ce.report.service.ICEReportDataSetService;
import com.ce.report.vo.ReportsQueryBaseVo;
import com.ce.util.DateUtil;

/**
 *许可证打印
 * @author 黄彦军
 */
public class LicenceService implements ICEReportDataSetService {

	private ICertificateManageService certificateManageService;

	public CEReportDataSet getReportDataSet(ReportsQueryBaseVo arg) throws CEReportException {

		LicenceQueryVO queryVO = (LicenceQueryVO) arg;

		return new CEReportDataSet(getData(queryVO),getImagepath(queryVO));
	}

	/**
	 * 功能描述: 获取打印数据 <br>
	 * @param queryVO
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2009-1-8  <br>
	 */
	public List<RenovateLicenceVO>  getData(LicenceQueryVO queryVO){
		RenovateLicenceVO licenceVO=certificateManageService.getLicenceByLicenceId(queryVO.getLicenceId());

		Date beginDate = licenceVO.getBeginDate();
		Date endDate = licenceVO.getEndDate();
		Double term= DateUtil.dateDiff("dd", beginDate, endDate);
		licenceVO.setTerm(term.intValue()+1);
		List<RenovateLicenceVO> list = new ArrayList<RenovateLicenceVO>();
		list.add(licenceVO);
		return list;
	}

	private Map<String, Object> getImagepath(LicenceQueryVO queryVO){
		Map<String, Object> map = new HashMap<String, Object>();

		String filePath = queryVO.getContextPath();
		filePath += "JasperReportFiles/ren_licence.jpg";
		map.put("image_path", filePath);

		return map;
	}

	public void setCertificateManageService(
			ICertificateManageService certificateManageService) {
		this.certificateManageService = certificateManageService;
	}


}
